<template>
  <div class="user-page">
    <div class="user">
      <img :src="userInfo.avatar" alt="" />
      <h3>{{ userInfo.username }}</h3>
    </div>
    <van-grid clickable :column-num="3" :border="false">
      <van-grid-item icon="clock-o" text="历史记录" to="/Layout/Article" />
      <van-grid-item icon="bookmark-o" text="我的收藏" to="/Layout/Collect" />
      <van-grid-item icon="thumb-circle-o" text="我的点赞" to="/Layout/like" />
    </van-grid>
    <van-cell-group class="mt20">
      <van-cell title="推荐分享" is-link />
      <van-cell title="意见反馈" is-link />
      <van-cell title="关于我们" is-link />
      <van-cell title="退出登录" is-link @click="logout" />
    </van-cell-group>
  </div>
</template>
<script>
import { currentUser_API } from "@/api/user.js";
import { delToken } from "@/utils/local-storage";
import { Dialog } from "vant";
export default {
  components: {
    [Dialog.Component.name]: Dialog.Component,
  },
  data() {
    return {
      userInfo: {},
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    // 获取用户信息
    async getUserInfo() {
      const { data } = await currentUser_API();
      this.userInfo = data.data;
    },
    async logout() {
      await Dialog.confirm({
        message: "确定退出登录吗？",
      })
        .then(() => {
          this.$toast.success("退出成功");
          delToken();
          this.$router.push({
            path: "/login",
          });
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="less" scoped>
.user-page {
  padding: 0 10px;
  background: #f5f5f5;
  height: calc(100vh - 50px);
  .mt20 {
    margin-top: 20px;
  }
  .user {
    display: flex;
    padding: 20px 0;
    align-items: center;
    img {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      overflow: hidden;
    }
    h3 {
      margin: 0;
      padding-left: 20px;
      font-size: 18px;
    }
  }
}
</style>